// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: '2024-03-01',
  devtools: {
    enabled: false,
  },

  modules: [
    '@nuxtjs/tailwindcss',
    'shadcn-nuxt',
    '@pinia/nuxt',
    '@nuxt/image',
    '@teages/nuxt-legacy',
  ],
  shadcn: {
    prefix: '',
    componentDir: './components/ui',
  },
  // 做低版本浏览器兼容性处理
  experimental: {
    entryImportMap: false,
  } as any,
  legacy: {
    vite: {
      targets: ['defaults', 'not IE 11', 'edge >= 84'],
      polyfills: true,
      renderLegacyChunks: true,
    },
  },

  // 运行时配置
  runtimeConfig: {
    // 私有配置，仅在服务端可用
    apiSecret: process.env.NUXT_API_SECRET || '',

    // 公共配置，客户端和服务端都可访问
    public: {
      apiBaseUrl: process.env.NUXT_PUBLIC_API_BASE_URL,
      apiTimeout: Number(process.env.NUXT_PUBLIC_API_TIMEOUT) || 10000,
      dbName: process.env.NUXT_PUBLIC_DB_NAME,
    },
  },
  nitro: {
    devProxy: {
      '/api': {
        target: process.env.NUXT_PUBLIC_API_BASE_URL,
        changeOrigin: true, // 允许跨域
        prependPath: true, // 保留路径前缀
      },
    },
  },
})
